package designpattern.composite;

import java.util.Objects;

/*
    组合学校、学院、专业的类
 */
public abstract class OrganizationComponent {
    private String name;    //组织名字
    private String dec; //组织描述

    public OrganizationComponent() {
    }

    public OrganizationComponent(String name, String dec) {
        this.name = name;
        this.dec = dec;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDec() {
        return dec;
    }

    public void setDec(String dec) {
        this.dec = dec;
    }

    //增加一个组织
    public void add(OrganizationComponent organizationComponent){
        //抛出不支持操作异常
        throw new UnsupportedOperationException();
    }

    //删除一个组织
    public void remove(OrganizationComponent organizationComponent){
        throw new UnsupportedOperationException();
    }

    //打印组织信息
    public abstract void print();

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        OrganizationComponent that = (OrganizationComponent) o;
        return name.equals(that.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name);
    }
}
